package com.wwz.service;

import com.wwz.clients.UserClient;
import com.wwz.mapper.OrderMapper;
import com.wwz.pojo.Order;
import com.wwz.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private UserClient userClient;
    /*@Autowired
    private RestTemplate restTemplate;*/

  /*  public Order queryOrderById(Long orderId){
        Order order = orderMapper.findById(orderId);
        //远程查询user,根据application的服务名访问
        String url = "http://nacos-user-server/user/"+order.getUserId();
        //发起调用
        User user = restTemplate.getForObject(url, User.class);
        order.setUser(user);
        return order;
    }*/

  //feign调用
  public Order findById(Long orderId){
      Order order = orderMapper.findOrderById(orderId);
      User user = userClient.findById(order.getUserId());
      order.setUser(user);
      return order;
  }
}
